//
//  HotAskDetailsCellView.m
//  SHHCPhone
//
//  Created by Sheng long on 14-9-21.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HotAskDetailsCellView.h"

#define CELL_HEAD_IMAGE_SIZE 27
#define CELL_HEAD_IMAGE_GAP  8

#define CELL_TEXT_FONT  [UIFont boldSystemFontOfSize:15]

#define CELL_ASK_HEAD_YGAP     5

#define CELL_REMARK_XGAP        8

#define CELL_ANSWER_ASK_YWIDTH      8
#define CELL_ANSWER_MAX_WIDTH(width)     (width - CELL_HEAD_IMAGE_GAP*2 - CELL_HEAD_IMAGE_SIZE)

@interface HotAskDetailsCellView()
{
    UIImageView *_headImage;
    UILabel *_nickLabel;
    UILabel *_remarkLabel;
    UILabel *_answerLabel;
}
@end

@implementation HotAskDetailsCellView

@synthesize isRedBg;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        _headImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"默认头像.png"]];
        [_headImage sizeToFit];
        [_headImage setCenter:CGPointMake(CELL_HEAD_IMAGE_GAP+_headImage.frame.size.width/2, CELL_HEAD_IMAGE_GAP+_headImage.frame.size.height/2)];
        [self addSubview:_headImage];
        [_headImage.layer setMasksToBounds:YES];
        [_headImage.layer setCornerRadius:_headImage.frame.size.width/2];
        
        _nickLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [_nickLabel setFont:CELL_TEXT_FONT];
        [_nickLabel setBackgroundColor:[UIColor clearColor]];
        [_nickLabel setTextColor:[UIColor blackColor]];
        [self addSubview:_nickLabel];
        
        _remarkLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [_remarkLabel setFont:CELL_TEXT_FONT];
        [_remarkLabel setBackgroundColor:[UIColor clearColor]];
        [_remarkLabel setTextColor:GET_COLOR(@"#bebebe")];
        [self addSubview:_remarkLabel];
        
        _answerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        [_answerLabel setFont:CELL_TEXT_FONT];
        [_answerLabel setBackgroundColor:[UIColor clearColor]];
        [_answerLabel setTextColor:GET_COLOR(@"#bebebe")];
        [_answerLabel setNumberOfLines:0];
        [self addSubview:_answerLabel];
    }
    return self;
}

-(void)setHeadImage:(NSString*)imageName nick:(NSString*)nick remark:(NSString*)remark answer:(NSString*)answer
{
    [_headImage setImageWithURL:[NSURL URLWithString:imageName] placeholderImage:[UIImage imageNamed:@"默认头像.png"]];
    
    [_remarkLabel setText:remark];
    [_remarkLabel sizeToFit];
    [_remarkLabel setFrame:CGRectMake(self.frame.size.width-CELL_REMARK_XGAP-_remarkLabel.frame.size.width, CELL_HEAD_IMAGE_GAP+CELL_ASK_HEAD_YGAP, _remarkLabel.frame.size.width, _remarkLabel.frame.size.height)];
    
    [_nickLabel setText:nick];
    [_nickLabel sizeToFit];
    CGSize size1 = [z_UI returnHeightFloat:nick frontSize:CELL_TEXT_FONT frontWidth:CGFLOAT_MAX];
    [_nickLabel setFrame:CGRectMake(CGRectGetMaxX(_headImage.frame)+CELL_HEAD_IMAGE_GAP, _remarkLabel.frame.origin.y, _remarkLabel.frame.origin.x-(CGRectGetMaxX(_headImage.frame)+CELL_HEAD_IMAGE_GAP), size1.height)];
    
    if (answer.length > 0) {
        [_answerLabel setText:answer];
        CGSize size2 = [z_UI returnHeightFloat:answer frontSize:CELL_TEXT_FONT frontWidth:CELL_ANSWER_MAX_WIDTH(self.frame.size.width)];
        [_answerLabel setFrame:CGRectMake(_nickLabel.frame.origin.x, CGRectGetMaxY(_nickLabel.frame)+CELL_ANSWER_ASK_YWIDTH, size2.width, size2.height)];
    }
}

+(CGFloat)getHeight:(NSString*)answer nick:(NSString*)nick width:(CGFloat)width
{
    CLog(@"nick======%@",[nick substringToIndex:1]);
    CGFloat y = 0;
    
    if (nick.length>0) {
        CGSize size1 = [z_UI returnHeightFloat:nick frontSize:CELL_TEXT_FONT frontWidth:CGFLOAT_MAX];
        y += (CELL_HEAD_IMAGE_GAP+CELL_ASK_HEAD_YGAP+size1.height+CELL_ANSWER_ASK_YWIDTH);
    }
    
    if (answer.length > 0) {
        CGSize size2 = [z_UI returnHeightFloat:answer frontSize:CELL_TEXT_FONT frontWidth:CELL_ANSWER_MAX_WIDTH(width)];
        y += size2.height;
    }
    
    return (y+=10);
}

@end
